package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;

import application.RenameType;

public class ProgressWindow extends JFrame implements ActionListener{
	
	private int numberOfImages;
	
	public ProgressWindow(int numberOfImages, RenameType type) {
		this.numberOfImages = numberOfImages;
		
		initComponents(type);
	}
	
	/**
	 * @param numberOfImages
	 * @param type
	 */
	private void initComponents(RenameType type) {
		getContentPane().setLayout(null);
		
		JLabel lblQuantidadeDeImagens = new JLabel("Quantidade de Imagens");
		lblQuantidadeDeImagens.setBounds(10, 11, 163, 14);
		getContentPane().add(lblQuantidadeDeImagens);
		
		finishedLabel = new JLabel("0/"+numberOfImages);
		finishedLabel.setBounds(183, 11, 124, 14);
		getContentPane().add(finishedLabel);
		
		JLabel lblTipoDeRenomeao = new JLabel("Tipo de Renomea\u00E7\u00E3o");
		lblTipoDeRenomeao.setBounds(10, 36, 163, 14);
		getContentPane().add(lblTipoDeRenomeao);
		
		typeLabel = new JLabel(String.valueOf(type));
		typeLabel.setBounds(183, 36, 124, 14);
		getContentPane().add(typeLabel);
		
		progressBar = new JProgressBar();
		progressBar.setBounds(10, 61, 314, 40);
		getContentPane().add(progressBar);
		
		closeButton = new JButton("Fechar");
		closeButton.setBounds(10, 108, 89, 23);
		closeButton.addActionListener(this);
		closeButton.setActionCommand("close");
		closeButton.setEnabled(false);
		getContentPane().add(closeButton);
		
		setSize(350,170);
		setVisible(true);
		setResizable(false);
		setLocationRelativeTo(null);
	}
	
	private static final long serialVersionUID = 1L;
	private JLabel finishedLabel;
	private JLabel typeLabel;
	private JProgressBar progressBar;
	private JButton closeButton;
	
	public void updateValues(int renamedImages){
		finishedLabel.setText(renamedImages+"/"+numberOfImages);
		
		double percentCompleted = 100*renamedImages/numberOfImages;
		
		progressBar.setValue((int)percentCompleted);
		if(percentCompleted == 100){
			closeButton.setEnabled(true);
		}
		
		repaint();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("close")){
			dispose();
		}
	}

	public JLabel getFinishedLabel() {
		return finishedLabel;
	}
	public JLabel getTypeLabel() {
		return typeLabel;
	}
	public JProgressBar getProgressBar() {
		return progressBar;
	}
	public JButton getCloseButton() {
		return closeButton;
	}
}
